//
//  TextMessageCell.swift
//  test-ios
//
//  Created by wyz5204 on 2023/7/28.
//

import Foundation
import YYText

// 显示文本的消息cell
class TextSendMessageCell : BaseSendMessageCell {
    
    private lazy var textView = {
        return YYLabel().then { label in
            label.numberOfLines = 0
            label.font = UIFont.systemFont(ofSize: 16)
        }
    }()
    
    override func initView() {
        super.initView()
        
        // 所有的文件添加到 容器中
        textView.addTo(containerView) { view in
            view.lineBreakMode = NSLineBreakMode.byCharWrapping
            view.preferredMaxLayoutWidth = SCREEN_WIDTH - 140;
            view.backgroundColor = .rd_blue
            view.layer.cornerRadius = 10.0
            view.layer.masksToBounds = true
            view.snp.makeConstraints { make in
                make.trailing.top.bottom.equalToSuperview()
                make.leading.equalToSuperview().offset(70)
            }
        }
    }
    
    override func initBinder(_ view: UITableView, _ data: ChatMessageBean, _ index: IndexPath) {
        super.initBinder(view, data, index)
        
        
        // 更新文本
        let textContainer = YYTextContainer()
        textContainer.size = CGSize(width: SCREEN_WIDTH - 140, height: CGFloat.greatestFiniteMagnitude)
        //        textContainer.maximumNumberOfRows = 0;
        // 设置内边距
        textContainer.insets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
        // 创建layout
        let textLayout = YYTextLayout(container: textContainer, text: data.ext.gl_toAttribute())
        
        
        textView.textLayout = textLayout
    }
}

class TextReceiveMessageCell : BaseReceiveMessageCell {
    
    
    private lazy var textView = {
        return YYLabel().then { label in
            label.numberOfLines = 0
            label.font = UIFont.systemFont(ofSize: 16)
        }
    }()
    
    override func initView() {
        super.initView()
        
        // 所有的文件添加到 容器中
        textView.addTo(containerView) { view in
            view.lineBreakMode = NSLineBreakMode.byCharWrapping
            view.preferredMaxLayoutWidth = SCREEN_WIDTH - 140;
            view.backgroundColor = .rd_blue
            view.layer.cornerRadius = 10.0
            view.layer.masksToBounds = true
            view.snp.makeConstraints { make in
                make.leading.top.bottom.equalToSuperview()
                make.trailing.equalToSuperview().offset(-70)
            }
        }
    }
    
    override func initBinder(_ view: UITableView, _ data: ChatMessageBean, _ index: IndexPath) {
        super.initBinder(view, data, index)
        
        
        // 更新文本
        let textContainer = YYTextContainer()
        textContainer.size = CGSize(width: SCREEN_WIDTH - 140, height: CGFloat.greatestFiniteMagnitude)
        //        textContainer.maximumNumberOfRows = 0;
        // 设置内边距
        textContainer.insets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
        // 创建layout
        let textLayout = YYTextLayout(container: textContainer, text: data.ext.gl_toAttribute())
        
        textView.textLayout = textLayout
    }
}

